<?php


namespace app\login\service;


use app\login\model\Account;
use app\login\model\Sign;

class FindSignService
{
    public function getSignByCondition($name, $post)
    {
        $page = $post['page'];
        $limit = $post['limit'];

                $filed = $post['field'];
        # 所有字段
        $data = ['signData','status','channel'];
        # 如果字段不存在则添加字段并设置值为空
        foreach ($data as $value){
            if(array_key_exists($value, $filed) == false){
                $filed[$value] = '';
            }
        }

        $arr = [
            'signData' => ['sign','=',$filed['signData']],
            'status'=> ['status', '=', $filed['status']],
            'channel'=> ['channel', '=', $filed['channel']],
        ];
        # 组装条件，首先是根据name来查找所有数据
        $where = [
//            '0' => ['from','=',$name]
        ];
        # 拼接where数组
        foreach ($filed as $key => $value){
            if($value == ''){
                unset($arr[$key]);
                continue;
            }
            array_push($where,$arr[$key]);
        }

        $model = new Sign();
        $page = new \Page\Page($model, $page, $limit, [], [], $where);
        $result = $page->layuiPage();
        return $result;
    }
}